<template>
  <div>
    <div class="button-container mt-3">
      <div class="btn-group">
        <button type="button" :class="active === 0 ? 'btn btn-primary' : 'btn btn-secondary'" @click="onClick(0)">全部
        </button>
        <button type="button" :class="active === 1 ? 'btn btn-primary' : 'btn btn-secondary'" @click="onClick(1)">已完成
        </button>
        <button type="button" :class="active === 2 ? 'btn btn-primary' : 'btn btn-secondary'" @click="onClick(2)">未完成
        </button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "TodoButton",
  props: {
    active: {
      type: Number,
      required: true,
      default: 0,
    }
  },
  emits: ["update:active"],
  data() {
    return {}
  },
  methods: {
    onClick(idx) {
      if (idx === this.active) {
        return;
      }
      this.$emit("update:active", idx);
    }
  }
}
</script>

<style lang="less" scoped>
.button-container {
  width: 400px;
  text-align: center;
}
</style>